{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 50,
   "id": "67de9e08",
   "metadata": {},
   "outputs": [],
   "source": [
    "%load_ext autoreload\n",
    "%autoreload 2"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "e1dbee7e",
   "metadata": {},
   "source": [
    "# The DIKW Pyramid\n",
    "\n",
    "## Data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "id": "b0e0de49",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><div id=2c346c13-448e-4ce4-a160-e64a46b5cf07 style=\"display:none; background-color:#9D6CFF; color:white; width:200px; height:30px; padding-left:5px; border-radius:4px; flex-direction:row; justify-content:space-around; align-items:center;\" onmouseover=\"this.style.backgroundColor='#BA9BF8'\" onmouseout=\"this.style.backgroundColor='#9D6CFF'\" onclick=\"window.commands?.execute('create-mitosheet-from-dataframe-output');\">See Full Dataframe in Mito</div> <script> if (window.commands.hasCommand('create-mitosheet-from-dataframe-output')) document.getElementById('2c346c13-448e-4ce4-a160-e64a46b5cf07').style.display = 'flex' </script> <table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>pet</th>\n",
       "      <th>number_of_participants</th>\n",
       "      <th>percentage</th>\n",
       "      <th>number_of_advertised_sites</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Cat</td>\n",
       "      <td>1138</td>\n",
       "      <td>88.560311</td>\n",
       "      <td>150</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Dog</td>\n",
       "      <td>130</td>\n",
       "      <td>10.116732</td>\n",
       "      <td>28</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Other</td>\n",
       "      <td>17</td>\n",
       "      <td>1.322957</td>\n",
       "      <td>147</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table></div>"
      ],
      "text/plain": [
       "     pet  number_of_participants  percentage  number_of_advertised_sites\n",
       "0    Cat                    1138   88.560311                         150\n",
       "1    Dog                     130   10.116732                          28\n",
       "2  Other                      17    1.322957                         147"
      ]
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "from config import *\n",
    "\n",
    "df = pd.read_csv('source/pets.csv')\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "id": "8c30cc3d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<style>\n",
       "  #altair-viz-32eebda3f35c4ff2828af5615d3ae4db.vega-embed {\n",
       "    width: 100%;\n",
       "    display: flex;\n",
       "  }\n",
       "\n",
       "  #altair-viz-32eebda3f35c4ff2828af5615d3ae4db.vega-embed details,\n",
       "  #altair-viz-32eebda3f35c4ff2828af5615d3ae4db.vega-embed details summary {\n",
       "    position: relative;\n",
       "  }\n",
       "</style>\n",
       "<div id=\"altair-viz-32eebda3f35c4ff2828af5615d3ae4db\"></div>\n",
       "<script type=\"text/javascript\">\n",
       "  var VEGA_DEBUG = (typeof VEGA_DEBUG == \"undefined\") ? {} : VEGA_DEBUG;\n",
       "  (function(spec, embedOpt){\n",
       "    let outputDiv = document.currentScript.previousElementSibling;\n",
       "    if (outputDiv.id !== \"altair-viz-32eebda3f35c4ff2828af5615d3ae4db\") {\n",
       "      outputDiv = document.getElementById(\"altair-viz-32eebda3f35c4ff2828af5615d3ae4db\");\n",
       "    }\n",
       "    const paths = {\n",
       "      \"vega\": \"https://cdn.jsdelivr.net/npm/vega@5?noext\",\n",
       "      \"vega-lib\": \"https://cdn.jsdelivr.net/npm/vega-lib?noext\",\n",
       "      \"vega-lite\": \"https://cdn.jsdelivr.net/npm/vega-lite@5.8.0?noext\",\n",
       "      \"vega-embed\": \"https://cdn.jsdelivr.net/npm/vega-embed@6?noext\",\n",
       "    };\n",
       "\n",
       "    function maybeLoadScript(lib, version) {\n",
       "      var key = `${lib.replace(\"-\", \"\")}_version`;\n",
       "      return (VEGA_DEBUG[key] == version) ?\n",
       "        Promise.resolve(paths[lib]) :\n",
       "        new Promise(function(resolve, reject) {\n",
       "          var s = document.createElement('script');\n",
       "          document.getElementsByTagName(\"head\")[0].appendChild(s);\n",
       "          s.async = true;\n",
       "          s.onload = () => {\n",
       "            VEGA_DEBUG[key] = version;\n",
       "            return resolve(paths[lib]);\n",
       "          };\n",
       "          s.onerror = () => reject(`Error loading script: ${paths[lib]}`);\n",
       "          s.src = paths[lib];\n",
       "        });\n",
       "    }\n",
       "\n",
       "    function showError(err) {\n",
       "      outputDiv.innerHTML = `<div class=\"error\" style=\"color:red;\">${err}</div>`;\n",
       "      throw err;\n",
       "    }\n",
       "\n",
       "    function displayChart(vegaEmbed) {\n",
       "      vegaEmbed(outputDiv, spec, embedOpt)\n",
       "        .catch(err => showError(`Javascript Error: ${err.message}<br>This usually means there's a typo in your chart specification. See the javascript console for the full traceback.`));\n",
       "    }\n",
       "\n",
       "    if(typeof define === \"function\" && define.amd) {\n",
       "      requirejs.config({paths});\n",
       "      require([\"vega-embed\"], displayChart, err => showError(`Error loading script: ${err.message}`));\n",
       "    } else {\n",
       "      maybeLoadScript(\"vega\", \"5\")\n",
       "        .then(() => maybeLoadScript(\"vega-lite\", \"5.8.0\"))\n",
       "        .then(() => maybeLoadScript(\"vega-embed\", \"6\"))\n",
       "        .catch(showError)\n",
       "        .then(() => displayChart(vegaEmbed));\n",
       "    }\n",
       "  })({\"config\": {\"view\": {\"continuousWidth\": 300, \"continuousHeight\": 300, \"strokeWidth\": 0}, \"axis\": {\"grid\": false, \"labelFontSize\": 15, \"titleFontSize\": 20}, \"title\": {\"fontSize\": 25}}, \"data\": {\"name\": \"data-6a77b92cd2438c485b88c059ddf09442\"}, \"mark\": {\"type\": \"bar\", \"color\": \"#636466\", \"size\": 100}, \"encoding\": {\"x\": {\"axis\": {\"labelAngle\": 0, \"title\": \"\"}, \"field\": \"pet\", \"type\": \"nominal\"}, \"y\": {\"field\": \"percentage\", \"type\": \"quantitative\"}}, \"height\": 300, \"title\": \"Percentage of Pets\", \"width\": 672, \"$schema\": \"https://vega.github.io/schema/vega-lite/v5.8.0.json\", \"datasets\": {\"data-6a77b92cd2438c485b88c059ddf09442\": [{\"pet\": \"Cat\", \"number_of_participants\": 1138, \"percentage\": 88.56031128, \"number_of_advertised_sites\": 150}, {\"pet\": \"Dog\", \"number_of_participants\": 130, \"percentage\": 10.11673152, \"number_of_advertised_sites\": 28}, {\"pet\": \"Other\", \"number_of_participants\": 17, \"percentage\": 1.322957198, \"number_of_advertised_sites\": 147}]}}, {\"mode\": \"vega-lite\"});\n",
       "</script>"
      ],
      "text/plain": [
       "alt.Chart(...)"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import altair as alt\n",
    "\n",
    "\n",
    "scale = alt.Scale(range=['#f77f00', '#fcbf49','#eae2b7'])\n",
    "\n",
    "chart = alt.Chart(df).mark_bar(size=100,color=color).encode(\n",
    "    x=alt.X('pet',axis=alt.Axis(labelAngle=0, title='')),\n",
    "    y=alt.Y('percentage'),\n",
    "\n",
    ").properties(width=width, height=height, title='Percentage of Pets')\n",
    "\n",
    "configure_layout(chart)"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "32f74f45",
   "metadata": {},
   "source": [
    "# Information"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "id": "f635d84b",
   "metadata": {},
   "outputs": [],
   "source": [
    "df.drop(index=[2],axis=0,inplace=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "id": "9a5de7b6",
   "metadata": {},
   "outputs": [],
   "source": [
    "df['percentage'] = df['percentage']/10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "id": "212de097",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><div id=d9ed7daf-ed0b-4c1e-8fe9-e06f178288eb style=\"display:none; background-color:#9D6CFF; color:white; width:200px; height:30px; padding-left:5px; border-radius:4px; flex-direction:row; justify-content:space-around; align-items:center;\" onmouseover=\"this.style.backgroundColor='#BA9BF8'\" onmouseout=\"this.style.backgroundColor='#9D6CFF'\" onclick=\"window.commands?.execute('create-mitosheet-from-dataframe-output');\">See Full Dataframe in Mito</div> <script> if (window.commands.hasCommand('create-mitosheet-from-dataframe-output')) document.getElementById('d9ed7daf-ed0b-4c1e-8fe9-e06f178288eb').style.display = 'flex' </script> <table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>pet</th>\n",
       "      <th>number_of_participants</th>\n",
       "      <th>percentage</th>\n",
       "      <th>number_of_advertised_sites</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Cat</td>\n",
       "      <td>1138</td>\n",
       "      <td>8.856031</td>\n",
       "      <td>150</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Dog</td>\n",
       "      <td>130</td>\n",
       "      <td>1.011673</td>\n",
       "      <td>28</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table></div>"
      ],
      "text/plain": [
       "   pet  number_of_participants  percentage  number_of_advertised_sites\n",
       "0  Cat                    1138    8.856031                         150\n",
       "1  Dog                     130    1.011673                          28"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "id": "0dc23894",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<style>\n",
       "  #altair-viz-adf9c3d4b3874f27a26659ca62267408.vega-embed {\n",
       "    width: 100%;\n",
       "    display: flex;\n",
       "  }\n",
       "\n",
       "  #altair-viz-adf9c3d4b3874f27a26659ca62267408.vega-embed details,\n",
       "  #altair-viz-adf9c3d4b3874f27a26659ca62267408.vega-embed details summary {\n",
       "    position: relative;\n",
       "  }\n",
       "</style>\n",
       "<div id=\"altair-viz-adf9c3d4b3874f27a26659ca62267408\"></div>\n",
       "<script type=\"text/javascript\">\n",
       "  var VEGA_DEBUG = (typeof VEGA_DEBUG == \"undefined\") ? {} : VEGA_DEBUG;\n",
       "  (function(spec, embedOpt){\n",
       "    let outputDiv = document.currentScript.previousElementSibling;\n",
       "    if (outputDiv.id !== \"altair-viz-adf9c3d4b3874f27a26659ca62267408\") {\n",
       "      outputDiv = document.getElementById(\"altair-viz-adf9c3d4b3874f27a26659ca62267408\");\n",
       "    }\n",
       "    const paths = {\n",
       "      \"vega\": \"https://cdn.jsdelivr.net/npm/vega@5?noext\",\n",
       "      \"vega-lib\": \"https://cdn.jsdelivr.net/npm/vega-lib?noext\",\n",
       "      \"vega-lite\": \"https://cdn.jsdelivr.net/npm/vega-lite@5.8.0?noext\",\n",
       "      \"vega-embed\": \"https://cdn.jsdelivr.net/npm/vega-embed@6?noext\",\n",
       "    };\n",
       "\n",
       "    function maybeLoadScript(lib, version) {\n",
       "      var key = `${lib.replace(\"-\", \"\")}_version`;\n",
       "      return (VEGA_DEBUG[key] == version) ?\n",
       "        Promise.resolve(paths[lib]) :\n",
       "        new Promise(function(resolve, reject) {\n",
       "          var s = document.createElement('script');\n",
       "          document.getElementsByTagName(\"head\")[0].appendChild(s);\n",
       "          s.async = true;\n",
       "          s.onload = () => {\n",
       "            VEGA_DEBUG[key] = version;\n",
       "            return resolve(paths[lib]);\n",
       "          };\n",
       "          s.onerror = () => reject(`Error loading script: ${paths[lib]}`);\n",
       "          s.src = paths[lib];\n",
       "        });\n",
       "    }\n",
       "\n",
       "    function showError(err) {\n",
       "      outputDiv.innerHTML = `<div class=\"error\" style=\"color:red;\">${err}</div>`;\n",
       "      throw err;\n",
       "    }\n",
       "\n",
       "    function displayChart(vegaEmbed) {\n",
       "      vegaEmbed(outputDiv, spec, embedOpt)\n",
       "        .catch(err => showError(`Javascript Error: ${err.message}<br>This usually means there's a typo in your chart specification. See the javascript console for the full traceback.`));\n",
       "    }\n",
       "\n",
       "    if(typeof define === \"function\" && define.amd) {\n",
       "      requirejs.config({paths});\n",
       "      require([\"vega-embed\"], displayChart, err => showError(`Error loading script: ${err.message}`));\n",
       "    } else {\n",
       "      maybeLoadScript(\"vega\", \"5\")\n",
       "        .then(() => maybeLoadScript(\"vega-lite\", \"5.8.0\"))\n",
       "        .then(() => maybeLoadScript(\"vega-embed\", \"6\"))\n",
       "        .catch(showError)\n",
       "        .then(() => displayChart(vegaEmbed));\n",
       "    }\n",
       "  })({\"config\": {\"view\": {\"continuousWidth\": 300, \"continuousHeight\": 300}}, \"data\": {\"name\": \"data-77785718e951b4397fc0a683964de4b5\"}, \"mark\": {\"type\": \"text\", \"fontSize\": 22}, \"encoding\": {\"color\": {\"field\": \"text\", \"legend\": null, \"scale\": {\"range\": [\"#636466\", \"#80C11E\"]}, \"type\": \"ordinal\"}, \"text\": {\"field\": \"text\", \"type\": \"nominal\"}, \"x\": {\"axis\": {\"grid\": false, \"orient\": \"bottom\", \"tickMinStep\": 1, \"title\": null}, \"field\": \"x\", \"scale\": {\"domain\": [0, 10]}, \"type\": \"quantitative\"}, \"y\": {\"value\": 30}}, \"$schema\": \"https://vega.github.io/schema/vega-lite/v5.8.0.json\", \"datasets\": {\"data-77785718e951b4397fc0a683964de4b5\": [{\"text\": \"cat\", \"x\": 0.5}, {\"text\": \"dog\", \"x\": 9.4}]}}, {\"mode\": \"vega-lite\"});\n",
       "</script>"
      ],
      "text/plain": [
       "alt.Chart(...)"
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data = pd.DataFrame([{'text' : 'cat', 'x': 0.5},\n",
    "                     {'text' : 'dog', 'x': 9.4}\n",
    "                    ])\n",
    "scale = alt.Scale(range=color2)\n",
    "text = alt.Chart(data).mark_text(\n",
    "    fontSize=textFontSize, \n",
    ").encode(\n",
    "    text='text:N',\n",
    "    x=alt.X('x:Q', scale=alt.Scale(domain=[0, 10]),axis=alt.Axis(tickMinStep = 1,grid=False, title=None, orient='bottom')),\n",
    "    y=alt.value(30),\n",
    "    color=alt.Color('text:O', scale = alt.Scale(range=color2), legend=None)\n",
    "    \n",
    ")\n",
    "\n",
    "text"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "id": "5a766fcd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<style>\n",
       "  #altair-viz-ccd0cd8e4f524b9e88e32971c9e35ea3.vega-embed {\n",
       "    width: 100%;\n",
       "    display: flex;\n",
       "  }\n",
       "\n",
       "  #altair-viz-ccd0cd8e4f524b9e88e32971c9e35ea3.vega-embed details,\n",
       "  #altair-viz-ccd0cd8e4f524b9e88e32971c9e35ea3.vega-embed details summary {\n",
       "    position: relative;\n",
       "  }\n",
       "</style>\n",
       "<div id=\"altair-viz-ccd0cd8e4f524b9e88e32971c9e35ea3\"></div>\n",
       "<script type=\"text/javascript\">\n",
       "  var VEGA_DEBUG = (typeof VEGA_DEBUG == \"undefined\") ? {} : VEGA_DEBUG;\n",
       "  (function(spec, embedOpt){\n",
       "    let outputDiv = document.currentScript.previousElementSibling;\n",
       "    if (outputDiv.id !== \"altair-viz-ccd0cd8e4f524b9e88e32971c9e35ea3\") {\n",
       "      outputDiv = document.getElementById(\"altair-viz-ccd0cd8e4f524b9e88e32971c9e35ea3\");\n",
       "    }\n",
       "    const paths = {\n",
       "      \"vega\": \"https://cdn.jsdelivr.net/npm/vega@5?noext\",\n",
       "      \"vega-lib\": \"https://cdn.jsdelivr.net/npm/vega-lib?noext\",\n",
       "      \"vega-lite\": \"https://cdn.jsdelivr.net/npm/vega-lite@5.8.0?noext\",\n",
       "      \"vega-embed\": \"https://cdn.jsdelivr.net/npm/vega-embed@6?noext\",\n",
       "    };\n",
       "\n",
       "    function maybeLoadScript(lib, version) {\n",
       "      var key = `${lib.replace(\"-\", \"\")}_version`;\n",
       "      return (VEGA_DEBUG[key] == version) ?\n",
       "        Promise.resolve(paths[lib]) :\n",
       "        new Promise(function(resolve, reject) {\n",
       "          var s = document.createElement('script');\n",
       "          document.getElementsByTagName(\"head\")[0].appendChild(s);\n",
       "          s.async = true;\n",
       "          s.onload = () => {\n",
       "            VEGA_DEBUG[key] = version;\n",
       "            return resolve(paths[lib]);\n",
       "          };\n",
       "          s.onerror = () => reject(`Error loading script: ${paths[lib]}`);\n",
       "          s.src = paths[lib];\n",
       "        });\n",
       "    }\n",
       "\n",
       "    function showError(err) {\n",
       "      outputDiv.innerHTML = `<div class=\"error\" style=\"color:red;\">${err}</div>`;\n",
       "      throw err;\n",
       "    }\n",
       "\n",
       "    function displayChart(vegaEmbed) {\n",
       "      vegaEmbed(outputDiv, spec, embedOpt)\n",
       "        .catch(err => showError(`Javascript Error: ${err.message}<br>This usually means there's a typo in your chart specification. See the javascript console for the full traceback.`));\n",
       "    }\n",
       "\n",
       "    if(typeof define === \"function\" && define.amd) {\n",
       "      requirejs.config({paths});\n",
       "      require([\"vega-embed\"], displayChart, err => showError(`Error loading script: ${err.message}`));\n",
       "    } else {\n",
       "      maybeLoadScript(\"vega\", \"5\")\n",
       "        .then(() => maybeLoadScript(\"vega-lite\", \"5.8.0\"))\n",
       "        .then(() => maybeLoadScript(\"vega-embed\", \"6\"))\n",
       "        .catch(showError)\n",
       "        .then(() => displayChart(vegaEmbed));\n",
       "    }\n",
       "  })({\"config\": {\"view\": {\"continuousWidth\": 300, \"continuousHeight\": 300, \"strokeOpacity\": 0}}, \"layer\": [{\"data\": {\"name\": \"data-77785718e951b4397fc0a683964de4b5\"}, \"mark\": {\"type\": \"text\", \"fontSize\": 22}, \"encoding\": {\"color\": {\"field\": \"text\", \"legend\": null, \"scale\": {\"range\": [\"#636466\", \"#80C11E\"]}, \"type\": \"ordinal\"}, \"text\": {\"field\": \"text\", \"type\": \"nominal\"}, \"x\": {\"axis\": {\"grid\": false, \"orient\": \"bottom\", \"tickMinStep\": 1, \"title\": null}, \"field\": \"x\", \"scale\": {\"domain\": [0, 10]}, \"type\": \"quantitative\"}, \"y\": {\"value\": 30}}}, {\"data\": {\"name\": \"data-8283f4e95429ecd9e9a39ab253b37f6e\"}, \"mark\": {\"type\": \"bar\", \"size\": 50}, \"encoding\": {\"color\": {\"field\": \"pet\", \"legend\": null, \"scale\": {\"range\": [\"#636466\", \"#80C11E\"]}, \"type\": \"ordinal\"}, \"opacity\": {\"value\": 0.6}, \"stroke\": {\"field\": \"pet\", \"legend\": null, \"scale\": {\"range\": [\"#636466\", \"#80C11E\"]}, \"type\": \"ordinal\"}, \"strokeWidth\": {\"value\": 2}, \"x\": {\"axis\": {\"grid\": false, \"orient\": \"bottom\", \"tickMinStep\": 1, \"title\": null}, \"field\": \"percentage\", \"scale\": {\"domain\": [0, 10]}, \"type\": \"quantitative\"}, \"y\": {\"value\": 80}}}], \"height\": 130, \"resolve\": {\"scale\": {\"color\": \"independent\"}}, \"$schema\": \"https://vega.github.io/schema/vega-lite/v5.8.0.json\", \"datasets\": {\"data-77785718e951b4397fc0a683964de4b5\": [{\"text\": \"cat\", \"x\": 0.5}, {\"text\": \"dog\", \"x\": 9.4}], \"data-8283f4e95429ecd9e9a39ab253b37f6e\": [{\"pet\": \"Cat\", \"number_of_participants\": 1138, \"percentage\": 8.856031128, \"number_of_advertised_sites\": 150}, {\"pet\": \"Dog\", \"number_of_participants\": 130, \"percentage\": 1.011673152, \"number_of_advertised_sites\": 28}]}}, {\"mode\": \"vega-lite\"});\n",
       "</script>"
      ],
      "text/plain": [
       "alt.LayerChart(...)"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "chart = alt.Chart(df).mark_bar(size=50\n",
    "    ).encode(\n",
    "    x=alt.X('percentage:Q', \n",
    "            scale=alt.Scale(domain=[0, 10]),\n",
    "            axis=alt.Axis(tickMinStep = 1,grid=False, title=None, orient='bottom')\n",
    "           ),\n",
    "    y=alt.value(80),\n",
    "    color=alt.Color('pet:O', legend=None,scale=scale),\n",
    "    stroke=alt.Color('pet:O',scale=scale, legend=None),\n",
    "    strokeWidth=alt.value(2),\n",
    "    opacity=alt.value(0.6)\n",
    "\n",
    ").properties(height=130)\n",
    "\n",
    "layer = alt.layer(\n",
    "    text,\n",
    "    chart\n",
    ").resolve_scale(\n",
    "    color='independent'\n",
    ").configure_view(\n",
    "    strokeOpacity=0\n",
    ").properties()\n",
    "\n",
    "layer"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "9fb8fc58",
   "metadata": {},
   "source": [
    "# Knowledge\n",
    "\n",
    "Calculate the participation rate in the event"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "id": "2e466dc5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><div id=db466e7b-9638-4d73-8560-635544c42e82 style=\"display:none; background-color:#9D6CFF; color:white; width:200px; height:30px; padding-left:5px; border-radius:4px; flex-direction:row; justify-content:space-around; align-items:center;\" onmouseover=\"this.style.backgroundColor='#BA9BF8'\" onmouseout=\"this.style.backgroundColor='#9D6CFF'\" onclick=\"window.commands?.execute('create-mitosheet-from-dataframe-output');\">See Full Dataframe in Mito</div> <script> if (window.commands.hasCommand('create-mitosheet-from-dataframe-output')) document.getElementById('db466e7b-9638-4d73-8560-635544c42e82').style.display = 'flex' </script> <table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>pet</th>\n",
       "      <th>number_of_participants</th>\n",
       "      <th>percentage</th>\n",
       "      <th>number_of_advertised_sites</th>\n",
       "      <th>participation_rate</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Cat</td>\n",
       "      <td>1138</td>\n",
       "      <td>8.856031</td>\n",
       "      <td>150</td>\n",
       "      <td>7.586667</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Dog</td>\n",
       "      <td>130</td>\n",
       "      <td>1.011673</td>\n",
       "      <td>28</td>\n",
       "      <td>4.642857</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table></div>"
      ],
      "text/plain": [
       "   pet  number_of_participants  percentage  number_of_advertised_sites  \\\n",
       "0  Cat                    1138    8.856031                         150   \n",
       "1  Dog                     130    1.011673                          28   \n",
       "\n",
       "   participation_rate  \n",
       "0            7.586667  \n",
       "1            4.642857  "
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['participation_rate'] = df['number_of_participants']/df['number_of_advertised_sites']\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 91,
   "id": "80a9239d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<style>\n",
       "  #altair-viz-2bdebb4714134297836013d3d0cb068c.vega-embed {\n",
       "    width: 100%;\n",
       "    display: flex;\n",
       "  }\n",
       "\n",
       "  #altair-viz-2bdebb4714134297836013d3d0cb068c.vega-embed details,\n",
       "  #altair-viz-2bdebb4714134297836013d3d0cb068c.vega-embed details summary {\n",
       "    position: relative;\n",
       "  }\n",
       "</style>\n",
       "<div id=\"altair-viz-2bdebb4714134297836013d3d0cb068c\"></div>\n",
       "<script type=\"text/javascript\">\n",
       "  var VEGA_DEBUG = (typeof VEGA_DEBUG == \"undefined\") ? {} : VEGA_DEBUG;\n",
       "  (function(spec, embedOpt){\n",
       "    let outputDiv = document.currentScript.previousElementSibling;\n",
       "    if (outputDiv.id !== \"altair-viz-2bdebb4714134297836013d3d0cb068c\") {\n",
       "      outputDiv = document.getElementById(\"altair-viz-2bdebb4714134297836013d3d0cb068c\");\n",
       "    }\n",
       "    const paths = {\n",
       "      \"vega\": \"https://cdn.jsdelivr.net/npm/vega@5?noext\",\n",
       "      \"vega-lib\": \"https://cdn.jsdelivr.net/npm/vega-lib?noext\",\n",
       "      \"vega-lite\": \"https://cdn.jsdelivr.net/npm/vega-lite@5.8.0?noext\",\n",
       "      \"vega-embed\": \"https://cdn.jsdelivr.net/npm/vega-embed@6?noext\",\n",
       "    };\n",
       "\n",
       "    function maybeLoadScript(lib, version) {\n",
       "      var key = `${lib.replace(\"-\", \"\")}_version`;\n",
       "      return (VEGA_DEBUG[key] == version) ?\n",
       "        Promise.resolve(paths[lib]) :\n",
       "        new Promise(function(resolve, reject) {\n",
       "          var s = document.createElement('script');\n",
       "          document.getElementsByTagName(\"head\")[0].appendChild(s);\n",
       "          s.async = true;\n",
       "          s.onload = () => {\n",
       "            VEGA_DEBUG[key] = version;\n",
       "            return resolve(paths[lib]);\n",
       "          };\n",
       "          s.onerror = () => reject(`Error loading script: ${paths[lib]}`);\n",
       "          s.src = paths[lib];\n",
       "        });\n",
       "    }\n",
       "\n",
       "    function showError(err) {\n",
       "      outputDiv.innerHTML = `<div class=\"error\" style=\"color:red;\">${err}</div>`;\n",
       "      throw err;\n",
       "    }\n",
       "\n",
       "    function displayChart(vegaEmbed) {\n",
       "      vegaEmbed(outputDiv, spec, embedOpt)\n",
       "        .catch(err => showError(`Javascript Error: ${err.message}<br>This usually means there's a typo in your chart specification. See the javascript console for the full traceback.`));\n",
       "    }\n",
       "\n",
       "    if(typeof define === \"function\" && define.amd) {\n",
       "      requirejs.config({paths});\n",
       "      require([\"vega-embed\"], displayChart, err => showError(`Error loading script: ${err.message}`));\n",
       "    } else {\n",
       "      maybeLoadScript(\"vega\", \"5\")\n",
       "        .then(() => maybeLoadScript(\"vega-lite\", \"5.8.0\"))\n",
       "        .then(() => maybeLoadScript(\"vega-embed\", \"6\"))\n",
       "        .catch(showError)\n",
       "        .then(() => displayChart(vegaEmbed));\n",
       "    }\n",
       "  })({\"config\": {\"view\": {\"continuousWidth\": 300, \"continuousHeight\": 300}}, \"data\": {\"name\": \"data-ec898dbcdcfc5738df234838b31e54e2\"}, \"mark\": {\"type\": \"text\", \"align\": \"left\", \"color\": \"#636466\", \"fontSize\": 20, \"y\": 0}, \"encoding\": {\"text\": {\"field\": \"text\", \"type\": \"nominal\"}}, \"$schema\": \"https://vega.github.io/schema/vega-lite/v5.8.0.json\", \"datasets\": {\"data-ec898dbcdcfc5738df234838b31e54e2\": [{\"text\": [\"The cats participation rate\", \"is almost 8%\", \"over 150 sites advertised,\", \"while the dogs participation rate\", \"is almost 5%\", \"over 30 sites advertised.\"]}]}}, {\"mode\": \"vega-lite\"});\n",
       "</script>"
      ],
      "text/plain": [
       "alt.Chart(...)"
      ]
     },
     "execution_count": 91,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text = [\"The cats participation rate\",\n",
    "        \"is almost 8%\",\n",
    "        \"over 150 sites advertised,\", \n",
    "        \"while the dogs participation rate\",\n",
    "        \"is almost 5%\",\n",
    "        \"over 30 sites advertised.\"]\n",
    "\n",
    "heading = pd.DataFrame([{'text' : text }])\n",
    "\n",
    "text = alt.Chart(heading).mark_text(\n",
    "    fontSize=20, \n",
    "    color=color,\n",
    "    align='left',\n",
    "    y = 0\n",
    ").encode(\n",
    "    text='text:N',\n",
    ")\n",
    "\n",
    "text"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 92,
   "id": "b193cc47",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<style>\n",
       "  #altair-viz-3a611a8cef4c497bb6cc12b14ac34a3b.vega-embed {\n",
       "    width: 100%;\n",
       "    display: flex;\n",
       "  }\n",
       "\n",
       "  #altair-viz-3a611a8cef4c497bb6cc12b14ac34a3b.vega-embed details,\n",
       "  #altair-viz-3a611a8cef4c497bb6cc12b14ac34a3b.vega-embed details summary {\n",
       "    position: relative;\n",
       "  }\n",
       "</style>\n",
       "<div id=\"altair-viz-3a611a8cef4c497bb6cc12b14ac34a3b\"></div>\n",
       "<script type=\"text/javascript\">\n",
       "  var VEGA_DEBUG = (typeof VEGA_DEBUG == \"undefined\") ? {} : VEGA_DEBUG;\n",
       "  (function(spec, embedOpt){\n",
       "    let outputDiv = document.currentScript.previousElementSibling;\n",
       "    if (outputDiv.id !== \"altair-viz-3a611a8cef4c497bb6cc12b14ac34a3b\") {\n",
       "      outputDiv = document.getElementById(\"altair-viz-3a611a8cef4c497bb6cc12b14ac34a3b\");\n",
       "    }\n",
       "    const paths = {\n",
       "      \"vega\": \"https://cdn.jsdelivr.net/npm/vega@5?noext\",\n",
       "      \"vega-lib\": \"https://cdn.jsdelivr.net/npm/vega-lib?noext\",\n",
       "      \"vega-lite\": \"https://cdn.jsdelivr.net/npm/vega-lite@5.8.0?noext\",\n",
       "      \"vega-embed\": \"https://cdn.jsdelivr.net/npm/vega-embed@6?noext\",\n",
       "    };\n",
       "\n",
       "    function maybeLoadScript(lib, version) {\n",
       "      var key = `${lib.replace(\"-\", \"\")}_version`;\n",
       "      return (VEGA_DEBUG[key] == version) ?\n",
       "        Promise.resolve(paths[lib]) :\n",
       "        new Promise(function(resolve, reject) {\n",
       "          var s = document.createElement('script');\n",
       "          document.getElementsByTagName(\"head\")[0].appendChild(s);\n",
       "          s.async = true;\n",
       "          s.onload = () => {\n",
       "            VEGA_DEBUG[key] = version;\n",
       "            return resolve(paths[lib]);\n",
       "          };\n",
       "          s.onerror = () => reject(`Error loading script: ${paths[lib]}`);\n",
       "          s.src = paths[lib];\n",
       "        });\n",
       "    }\n",
       "\n",
       "    function showError(err) {\n",
       "      outputDiv.innerHTML = `<div class=\"error\" style=\"color:red;\">${err}</div>`;\n",
       "      throw err;\n",
       "    }\n",
       "\n",
       "    function displayChart(vegaEmbed) {\n",
       "      vegaEmbed(outputDiv, spec, embedOpt)\n",
       "        .catch(err => showError(`Javascript Error: ${err.message}<br>This usually means there's a typo in your chart specification. See the javascript console for the full traceback.`));\n",
       "    }\n",
       "\n",
       "    if(typeof define === \"function\" && define.amd) {\n",
       "      requirejs.config({paths});\n",
       "      require([\"vega-embed\"], displayChart, err => showError(`Error loading script: ${err.message}`));\n",
       "    } else {\n",
       "      maybeLoadScript(\"vega\", \"5\")\n",
       "        .then(() => maybeLoadScript(\"vega-lite\", \"5.8.0\"))\n",
       "        .then(() => maybeLoadScript(\"vega-embed\", \"6\"))\n",
       "        .catch(showError)\n",
       "        .then(() => displayChart(vegaEmbed));\n",
       "    }\n",
       "  })({\"config\": {\"view\": {\"continuousWidth\": 300, \"continuousHeight\": 300, \"strokeWidth\": 0}, \"axis\": {\"grid\": false, \"labelFontSize\": 15, \"titleFontSize\": 20}, \"title\": {\"fontSize\": 25}}, \"hconcat\": [{\"data\": {\"name\": \"data-ec898dbcdcfc5738df234838b31e54e2\"}, \"mark\": {\"type\": \"text\", \"align\": \"left\", \"color\": \"#636466\", \"fontSize\": 20, \"y\": 0}, \"encoding\": {\"text\": {\"field\": \"text\", \"type\": \"nominal\"}}}, {\"data\": {\"name\": \"data-eed7b3246ab042143a76f3352fafd93c\"}, \"mark\": {\"type\": \"bar\", \"size\": 50}, \"encoding\": {\"color\": {\"field\": \"pet\", \"legend\": null, \"scale\": {\"range\": [\"#636466\", \"#80C11E\"]}, \"type\": \"ordinal\"}, \"opacity\": {\"value\": 0.6}, \"stroke\": {\"field\": \"pet\", \"legend\": null, \"scale\": {\"range\": [\"#636466\", \"#80C11E\"]}, \"type\": \"ordinal\"}, \"strokeWidth\": {\"value\": 2}, \"x\": {\"axis\": {\"grid\": false, \"orient\": \"bottom\", \"tickMinStep\": 1, \"title\": null}, \"field\": \"percentage\", \"scale\": {\"domain\": [0, 10]}, \"type\": \"quantitative\"}, \"y\": {\"value\": 80}}, \"height\": 120, \"title\": \"9 pets out of 10 are cats\"}], \"$schema\": \"https://vega.github.io/schema/vega-lite/v5.8.0.json\", \"datasets\": {\"data-ec898dbcdcfc5738df234838b31e54e2\": [{\"text\": [\"The cats participation rate\", \"is almost 8%\", \"over 150 sites advertised,\", \"while the dogs participation rate\", \"is almost 5%\", \"over 30 sites advertised.\"]}], \"data-eed7b3246ab042143a76f3352fafd93c\": [{\"pet\": \"Cat\", \"number_of_participants\": 1138, \"percentage\": 8.856031128, \"number_of_advertised_sites\": 150, \"participation_rate\": 7.586666666666667}, {\"pet\": \"Dog\", \"number_of_participants\": 130, \"percentage\": 1.011673152, \"number_of_advertised_sites\": 28, \"participation_rate\": 4.642857142857143}]}}, {\"mode\": \"vega-lite\"});\n",
       "</script>"
      ],
      "text/plain": [
       "alt.HConcatChart(...)"
      ]
     },
     "execution_count": 92,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "chart = chart.properties(\n",
    "    height=120,\n",
    "    title='9 pets out of 10 are cats',\n",
    ")\n",
    "\n",
    "layer2 = text | chart\n",
    "\n",
    "\n",
    "\n",
    "configure_layout(layer2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 93,
   "id": "40c516df",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<style>\n",
       "  #altair-viz-3f9e7078585641c58b2ab20c76351aa4.vega-embed {\n",
       "    width: 100%;\n",
       "    display: flex;\n",
       "  }\n",
       "\n",
       "  #altair-viz-3f9e7078585641c58b2ab20c76351aa4.vega-embed details,\n",
       "  #altair-viz-3f9e7078585641c58b2ab20c76351aa4.vega-embed details summary {\n",
       "    position: relative;\n",
       "  }\n",
       "</style>\n",
       "<div id=\"altair-viz-3f9e7078585641c58b2ab20c76351aa4\"></div>\n",
       "<script type=\"text/javascript\">\n",
       "  var VEGA_DEBUG = (typeof VEGA_DEBUG == \"undefined\") ? {} : VEGA_DEBUG;\n",
       "  (function(spec, embedOpt){\n",
       "    let outputDiv = document.currentScript.previousElementSibling;\n",
       "    if (outputDiv.id !== \"altair-viz-3f9e7078585641c58b2ab20c76351aa4\") {\n",
       "      outputDiv = document.getElementById(\"altair-viz-3f9e7078585641c58b2ab20c76351aa4\");\n",
       "    }\n",
       "    const paths = {\n",
       "      \"vega\": \"https://cdn.jsdelivr.net/npm/vega@5?noext\",\n",
       "      \"vega-lib\": \"https://cdn.jsdelivr.net/npm/vega-lib?noext\",\n",
       "      \"vega-lite\": \"https://cdn.jsdelivr.net/npm/vega-lite@5.8.0?noext\",\n",
       "      \"vega-embed\": \"https://cdn.jsdelivr.net/npm/vega-embed@6?noext\",\n",
       "    };\n",
       "\n",
       "    function maybeLoadScript(lib, version) {\n",
       "      var key = `${lib.replace(\"-\", \"\")}_version`;\n",
       "      return (VEGA_DEBUG[key] == version) ?\n",
       "        Promise.resolve(paths[lib]) :\n",
       "        new Promise(function(resolve, reject) {\n",
       "          var s = document.createElement('script');\n",
       "          document.getElementsByTagName(\"head\")[0].appendChild(s);\n",
       "          s.async = true;\n",
       "          s.onload = () => {\n",
       "            VEGA_DEBUG[key] = version;\n",
       "            return resolve(paths[lib]);\n",
       "          };\n",
       "          s.onerror = () => reject(`Error loading script: ${paths[lib]}`);\n",
       "          s.src = paths[lib];\n",
       "        });\n",
       "    }\n",
       "\n",
       "    function showError(err) {\n",
       "      outputDiv.innerHTML = `<div class=\"error\" style=\"color:red;\">${err}</div>`;\n",
       "      throw err;\n",
       "    }\n",
       "\n",
       "    function displayChart(vegaEmbed) {\n",
       "      vegaEmbed(outputDiv, spec, embedOpt)\n",
       "        .catch(err => showError(`Javascript Error: ${err.message}<br>This usually means there's a typo in your chart specification. See the javascript console for the full traceback.`));\n",
       "    }\n",
       "\n",
       "    if(typeof define === \"function\" && define.amd) {\n",
       "      requirejs.config({paths});\n",
       "      require([\"vega-embed\"], displayChart, err => showError(`Error loading script: ${err.message}`));\n",
       "    } else {\n",
       "      maybeLoadScript(\"vega\", \"5\")\n",
       "        .then(() => maybeLoadScript(\"vega-lite\", \"5.8.0\"))\n",
       "        .then(() => maybeLoadScript(\"vega-embed\", \"6\"))\n",
       "        .catch(showError)\n",
       "        .then(() => displayChart(vegaEmbed));\n",
       "    }\n",
       "  })({\"config\": {\"view\": {\"continuousWidth\": 300, \"continuousHeight\": 300}}, \"data\": {\"name\": \"data-8e3a1bd2af825c56ce37658f6a89ed02\"}, \"mark\": {\"type\": \"image\", \"height\": 50, \"width\": 50, \"y\": 50}, \"encoding\": {\"url\": {\"field\": \"img\", \"type\": \"nominal\"}, \"x\": {\"axis\": {\"grid\": false, \"orient\": \"bottom\", \"tickMinStep\": 1, \"title\": null}, \"field\": \"x\", \"scale\": {\"domain\": [0, 10]}, \"type\": \"quantitative\"}}, \"$schema\": \"https://vega.github.io/schema/vega-lite/v5.8.0.json\", \"datasets\": {\"data-8e3a1bd2af825c56ce37658f6a89ed02\": [{\"x\": 0.0, \"img\": \"img/cat.png\"}, {\"x\": 9.8, \"img\": \"img/dog.png\"}]}}, {\"mode\": \"vega-lite\"});\n",
       "</script>"
      ],
      "text/plain": [
       "alt.Chart(...)"
      ]
     },
     "execution_count": 93,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "source = pd.DataFrame.from_records([\n",
    "      {\"x\": 0, \"img\": \"images/cat.png\"},\n",
    "      {\"x\": 9.8, \"img\": \"images/dog.png\"}\n",
    "])\n",
    "\n",
    "img = alt.Chart(source).mark_image(\n",
    "    width=50,\n",
    "    height=50,\n",
    "    y=50\n",
    ").encode(\n",
    "    x=alt.X('x:Q', scale=alt.Scale(domain=[0, 10]),axis=alt.Axis(tickMinStep = 1,grid=False, title=None, orient='bottom')),\n",
    "    url='img',\n",
    "    \n",
    ")\n",
    "\n",
    "img"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 94,
   "id": "07d2d2ee",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<style>\n",
       "  #altair-viz-78bf31fa41cd4e79a3448999a5c0cf58.vega-embed {\n",
       "    width: 100%;\n",
       "    display: flex;\n",
       "  }\n",
       "\n",
       "  #altair-viz-78bf31fa41cd4e79a3448999a5c0cf58.vega-embed details,\n",
       "  #altair-viz-78bf31fa41cd4e79a3448999a5c0cf58.vega-embed details summary {\n",
       "    position: relative;\n",
       "  }\n",
       "</style>\n",
       "<div id=\"altair-viz-78bf31fa41cd4e79a3448999a5c0cf58\"></div>\n",
       "<script type=\"text/javascript\">\n",
       "  var VEGA_DEBUG = (typeof VEGA_DEBUG == \"undefined\") ? {} : VEGA_DEBUG;\n",
       "  (function(spec, embedOpt){\n",
       "    let outputDiv = document.currentScript.previousElementSibling;\n",
       "    if (outputDiv.id !== \"altair-viz-78bf31fa41cd4e79a3448999a5c0cf58\") {\n",
       "      outputDiv = document.getElementById(\"altair-viz-78bf31fa41cd4e79a3448999a5c0cf58\");\n",
       "    }\n",
       "    const paths = {\n",
       "      \"vega\": \"https://cdn.jsdelivr.net/npm/vega@5?noext\",\n",
       "      \"vega-lib\": \"https://cdn.jsdelivr.net/npm/vega-lib?noext\",\n",
       "      \"vega-lite\": \"https://cdn.jsdelivr.net/npm/vega-lite@5.8.0?noext\",\n",
       "      \"vega-embed\": \"https://cdn.jsdelivr.net/npm/vega-embed@6?noext\",\n",
       "    };\n",
       "\n",
       "    function maybeLoadScript(lib, version) {\n",
       "      var key = `${lib.replace(\"-\", \"\")}_version`;\n",
       "      return (VEGA_DEBUG[key] == version) ?\n",
       "        Promise.resolve(paths[lib]) :\n",
       "        new Promise(function(resolve, reject) {\n",
       "          var s = document.createElement('script');\n",
       "          document.getElementsByTagName(\"head\")[0].appendChild(s);\n",
       "          s.async = true;\n",
       "          s.onload = () => {\n",
       "            VEGA_DEBUG[key] = version;\n",
       "            return resolve(paths[lib]);\n",
       "          };\n",
       "          s.onerror = () => reject(`Error loading script: ${paths[lib]}`);\n",
       "          s.src = paths[lib];\n",
       "        });\n",
       "    }\n",
       "\n",
       "    function showError(err) {\n",
       "      outputDiv.innerHTML = `<div class=\"error\" style=\"color:red;\">${err}</div>`;\n",
       "      throw err;\n",
       "    }\n",
       "\n",
       "    function displayChart(vegaEmbed) {\n",
       "      vegaEmbed(outputDiv, spec, embedOpt)\n",
       "        .catch(err => showError(`Javascript Error: ${err.message}<br>This usually means there's a typo in your chart specification. See the javascript console for the full traceback.`));\n",
       "    }\n",
       "\n",
       "    if(typeof define === \"function\" && define.amd) {\n",
       "      requirejs.config({paths});\n",
       "      require([\"vega-embed\"], displayChart, err => showError(`Error loading script: ${err.message}`));\n",
       "    } else {\n",
       "      maybeLoadScript(\"vega\", \"5\")\n",
       "        .then(() => maybeLoadScript(\"vega-lite\", \"5.8.0\"))\n",
       "        .then(() => maybeLoadScript(\"vega-embed\", \"6\"))\n",
       "        .catch(showError)\n",
       "        .then(() => displayChart(vegaEmbed));\n",
       "    }\n",
       "  })({\"config\": {\"view\": {\"continuousWidth\": 300, \"continuousHeight\": 300, \"strokeWidth\": 0}, \"axis\": {\"grid\": false, \"labelFontSize\": 15, \"titleFontSize\": 20}, \"title\": {\"fontSize\": 25}}, \"hconcat\": [{\"data\": {\"name\": \"data-ec898dbcdcfc5738df234838b31e54e2\"}, \"mark\": {\"type\": \"text\", \"align\": \"left\", \"color\": \"#636466\", \"fontSize\": 20, \"y\": 0}, \"encoding\": {\"text\": {\"field\": \"text\", \"type\": \"nominal\"}}}, {\"layer\": [{\"data\": {\"name\": \"data-eed7b3246ab042143a76f3352fafd93c\"}, \"mark\": {\"type\": \"bar\", \"size\": 50}, \"encoding\": {\"color\": {\"field\": \"pet\", \"legend\": null, \"scale\": {\"range\": [\"#636466\", \"#80C11E\"]}, \"type\": \"ordinal\"}, \"opacity\": {\"value\": 0.6}, \"stroke\": {\"field\": \"pet\", \"legend\": null, \"scale\": {\"range\": [\"#636466\", \"#80C11E\"]}, \"type\": \"ordinal\"}, \"strokeWidth\": {\"value\": 2}, \"x\": {\"axis\": {\"grid\": false, \"orient\": \"bottom\", \"tickMinStep\": 1, \"title\": null}, \"field\": \"percentage\", \"scale\": {\"domain\": [0, 10]}, \"type\": \"quantitative\"}, \"y\": {\"value\": 80}}, \"title\": \"9 pets out of 10 are cats\"}, {\"data\": {\"name\": \"data-8e3a1bd2af825c56ce37658f6a89ed02\"}, \"mark\": {\"type\": \"image\", \"height\": 50, \"width\": 50, \"y\": 50}, \"encoding\": {\"url\": {\"field\": \"img\", \"type\": \"nominal\"}, \"x\": {\"axis\": {\"grid\": false, \"orient\": \"bottom\", \"tickMinStep\": 1, \"title\": null}, \"field\": \"x\", \"scale\": {\"domain\": [0, 10]}, \"type\": \"quantitative\"}}}], \"height\": 120}], \"resolve\": {\"scale\": {\"color\": \"independent\"}}, \"$schema\": \"https://vega.github.io/schema/vega-lite/v5.8.0.json\", \"datasets\": {\"data-ec898dbcdcfc5738df234838b31e54e2\": [{\"text\": [\"The cats participation rate\", \"is almost 8%\", \"over 150 sites advertised,\", \"while the dogs participation rate\", \"is almost 5%\", \"over 30 sites advertised.\"]}], \"data-eed7b3246ab042143a76f3352fafd93c\": [{\"pet\": \"Cat\", \"number_of_participants\": 1138, \"percentage\": 8.856031128, \"number_of_advertised_sites\": 150, \"participation_rate\": 7.586666666666667}, {\"pet\": \"Dog\", \"number_of_participants\": 130, \"percentage\": 1.011673152, \"number_of_advertised_sites\": 28, \"participation_rate\": 4.642857142857143}], \"data-8e3a1bd2af825c56ce37658f6a89ed02\": [{\"x\": 0.0, \"img\": \"img/cat.png\"}, {\"x\": 9.8, \"img\": \"img/dog.png\"}]}}, {\"mode\": \"vega-lite\"});\n",
       "</script>"
      ],
      "text/plain": [
       "alt.HConcatChart(...)"
      ]
     },
     "execution_count": 94,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "layer3 = (text | chart + img\n",
    ").resolve_scale(\n",
    "    color='independent'\n",
    ").configure_view(\n",
    "    strokeOpacity=0\n",
    ")\n",
    "configure_layout(layer3)"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "1650dd9f",
   "metadata": {},
   "source": [
    "# Wisdom"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 95,
   "id": "4b926b8b",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<style>\n",
       "  #altair-viz-5c61426189bc40b0b19ae07f81149d9e.vega-embed {\n",
       "    width: 100%;\n",
       "    display: flex;\n",
       "  }\n",
       "\n",
       "  #altair-viz-5c61426189bc40b0b19ae07f81149d9e.vega-embed details,\n",
       "  #altair-viz-5c61426189bc40b0b19ae07f81149d9e.vega-embed details summary {\n",
       "    position: relative;\n",
       "  }\n",
       "</style>\n",
       "<div id=\"altair-viz-5c61426189bc40b0b19ae07f81149d9e\"></div>\n",
       "<script type=\"text/javascript\">\n",
       "  var VEGA_DEBUG = (typeof VEGA_DEBUG == \"undefined\") ? {} : VEGA_DEBUG;\n",
       "  (function(spec, embedOpt){\n",
       "    let outputDiv = document.currentScript.previousElementSibling;\n",
       "    if (outputDiv.id !== \"altair-viz-5c61426189bc40b0b19ae07f81149d9e\") {\n",
       "      outputDiv = document.getElementById(\"altair-viz-5c61426189bc40b0b19ae07f81149d9e\");\n",
       "    }\n",
       "    const paths = {\n",
       "      \"vega\": \"https://cdn.jsdelivr.net/npm/vega@5?noext\",\n",
       "      \"vega-lib\": \"https://cdn.jsdelivr.net/npm/vega-lib?noext\",\n",
       "      \"vega-lite\": \"https://cdn.jsdelivr.net/npm/vega-lite@5.8.0?noext\",\n",
       "      \"vega-embed\": \"https://cdn.jsdelivr.net/npm/vega-embed@6?noext\",\n",
       "    };\n",
       "\n",
       "    function maybeLoadScript(lib, version) {\n",
       "      var key = `${lib.replace(\"-\", \"\")}_version`;\n",
       "      return (VEGA_DEBUG[key] == version) ?\n",
       "        Promise.resolve(paths[lib]) :\n",
       "        new Promise(function(resolve, reject) {\n",
       "          var s = document.createElement('script');\n",
       "          document.getElementsByTagName(\"head\")[0].appendChild(s);\n",
       "          s.async = true;\n",
       "          s.onload = () => {\n",
       "            VEGA_DEBUG[key] = version;\n",
       "            return resolve(paths[lib]);\n",
       "          };\n",
       "          s.onerror = () => reject(`Error loading script: ${paths[lib]}`);\n",
       "          s.src = paths[lib];\n",
       "        });\n",
       "    }\n",
       "\n",
       "    function showError(err) {\n",
       "      outputDiv.innerHTML = `<div class=\"error\" style=\"color:red;\">${err}</div>`;\n",
       "      throw err;\n",
       "    }\n",
       "\n",
       "    function displayChart(vegaEmbed) {\n",
       "      vegaEmbed(outputDiv, spec, embedOpt)\n",
       "        .catch(err => showError(`Javascript Error: ${err.message}<br>This usually means there's a typo in your chart specification. See the javascript console for the full traceback.`));\n",
       "    }\n",
       "\n",
       "    if(typeof define === \"function\" && define.amd) {\n",
       "      requirejs.config({paths});\n",
       "      require([\"vega-embed\"], displayChart, err => showError(`Error loading script: ${err.message}`));\n",
       "    } else {\n",
       "      maybeLoadScript(\"vega\", \"5\")\n",
       "        .then(() => maybeLoadScript(\"vega-lite\", \"5.8.0\"))\n",
       "        .then(() => maybeLoadScript(\"vega-embed\", \"6\"))\n",
       "        .catch(showError)\n",
       "        .then(() => displayChart(vegaEmbed));\n",
       "    }\n",
       "  })({\"config\": {\"view\": {\"continuousWidth\": 300, \"continuousHeight\": 300, \"strokeWidth\": 0}, \"axis\": {\"grid\": false, \"labelFontSize\": 15, \"titleFontSize\": 20}, \"title\": {\"fontSize\": 25}}, \"hconcat\": [{\"data\": {\"name\": \"data-ec898dbcdcfc5738df234838b31e54e2\"}, \"mark\": {\"type\": \"text\", \"align\": \"left\", \"color\": \"#636466\", \"fontSize\": 20, \"y\": 0}, \"encoding\": {\"text\": {\"field\": \"text\", \"type\": \"nominal\"}}}, {\"layer\": [{\"data\": {\"name\": \"data-eed7b3246ab042143a76f3352fafd93c\"}, \"mark\": {\"type\": \"bar\", \"size\": 50}, \"encoding\": {\"color\": {\"field\": \"pet\", \"legend\": null, \"scale\": {\"range\": [\"#636466\", \"#80C11E\"]}, \"type\": \"ordinal\"}, \"opacity\": {\"value\": 0.6}, \"stroke\": {\"field\": \"pet\", \"legend\": null, \"scale\": {\"range\": [\"#636466\", \"#80C11E\"]}, \"type\": \"ordinal\"}, \"strokeWidth\": {\"value\": 2}, \"x\": {\"axis\": {\"grid\": false, \"orient\": \"bottom\", \"tickMinStep\": 1, \"title\": null}, \"field\": \"percentage\", \"scale\": {\"domain\": [0, 10]}, \"type\": \"quantitative\"}, \"y\": {\"value\": 80}}, \"title\": [\"Increase the advertising campaign\", \"on dog-related websites!\"]}, {\"data\": {\"name\": \"data-8e3a1bd2af825c56ce37658f6a89ed02\"}, \"mark\": {\"type\": \"image\", \"height\": 50, \"width\": 50, \"y\": 50}, \"encoding\": {\"url\": {\"field\": \"img\", \"type\": \"nominal\"}, \"x\": {\"axis\": {\"grid\": false, \"orient\": \"bottom\", \"tickMinStep\": 1, \"title\": null}, \"field\": \"x\", \"scale\": {\"domain\": [0, 10]}, \"type\": \"quantitative\"}}}], \"height\": 120}], \"resolve\": {\"scale\": {\"color\": \"independent\"}}, \"$schema\": \"https://vega.github.io/schema/vega-lite/v5.8.0.json\", \"datasets\": {\"data-ec898dbcdcfc5738df234838b31e54e2\": [{\"text\": [\"The cats participation rate\", \"is almost 8%\", \"over 150 sites advertised,\", \"while the dogs participation rate\", \"is almost 5%\", \"over 30 sites advertised.\"]}], \"data-eed7b3246ab042143a76f3352fafd93c\": [{\"pet\": \"Cat\", \"number_of_participants\": 1138, \"percentage\": 8.856031128, \"number_of_advertised_sites\": 150, \"participation_rate\": 7.586666666666667}, {\"pet\": \"Dog\", \"number_of_participants\": 130, \"percentage\": 1.011673152, \"number_of_advertised_sites\": 28, \"participation_rate\": 4.642857142857143}], \"data-8e3a1bd2af825c56ce37658f6a89ed02\": [{\"x\": 0.0, \"img\": \"img/cat.png\"}, {\"x\": 9.8, \"img\": \"img/dog.png\"}]}}, {\"mode\": \"vega-lite\"});\n",
       "</script>"
      ],
      "text/plain": [
       "alt.HConcatChart(...)"
      ]
     },
     "execution_count": 95,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "chart = chart.properties(\n",
    "    title=['Increase the advertising campaign', 'on dog-related websites!'],\n",
    "    height=120\n",
    ")\n",
    "\n",
    "layer3 = (text | chart + img\n",
    ").resolve_scale(\n",
    "    color='independent'\n",
    ").configure_view(\n",
    "    strokeOpacity=0\n",
    ").configure_title(fontSize=24,color=\"#003049\")\n",
    "\n",
    "configure_layout(layer3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "50cf105b",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b710d5c8",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
